package com.atguigu.gmall.payment.strategy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author: atguigu
 * @create: 2023-07-03 16:59
 */
@Component
public class StrategyConfig {

    /**
     * 会自动从IOC容器中获取 PayApi 类型对象,自动注入Map中
     * Map中key:是对象bean的ID Map中Val 是对象本身
     */
    @Autowired
    private Map<String, PayApi> payApiMap;


    /**
     * 根据支付方式获取支付实现类
     *
     * @param payType
     * @return
     */
    public PayApi getStrategyByType(String payType) {
        if (payApiMap.containsKey(payType)) {
            return payApiMap.get(payType);
        }
        throw new RuntimeException("不支持此方式");
    }


}
